//GameStateManager class
#include "GameStateManager.h"
#include "GameStateIntro.h"
#include "GameStateMap.h"
#include "GameStateBattle.h"

//Gamestate
GameState* GameStateManager::ActiveGameState = 0;

//OnEvent
void GameStateManager::OnEvent(SDL_Event* EventHolder) {
    if(ActiveGameState) ActiveGameState->OnEvent(EventHolder);
}

//OnLoop-
void GameStateManager::OnLoop() {
    if(ActiveGameState) ActiveGameState->OnLoop();
}

//OnRender
void GameStateManager::OnRender(SDL_Surface* Surf_Display) {
    if(ActiveGameState) ActiveGameState->OnRender(Surf_Display);
}

//SetActiveGameState
void GameStateManager::SetActiveGameState(int GameStateID) {
    if(ActiveGameState)
        ActiveGameState->OnDeactivate();

    //List of app states
    if(GameStateID == GAMESTATE_INTRO)
        ActiveGameState = GameStateIntro::GetInstance();
    else if(GameStateID == GAMESTATE_MAP)
        ActiveGameState = GameStateMap::GetInstance();
    else if(GameStateID == GAMESTATE_BATTLE)
        ActiveGameState = GameStateBattle::GetInstance();
    else//(GameStateID == GAMESTATE_NONE)
        ActiveGameState = 0;
    if(ActiveGameState == 0)
        exit(1);
    if(ActiveGameState)
        ActiveGameState->OnActivate();
}

//GetActiveGameState
GameState* GameStateManager::GetActiveGameState() {
    return ActiveGameState;
}

